// 封装fetch请求
const http = {
  // get请求
  get: function get(url, parmas) {
    if (parmas) {
      let str = JSON.stringify(parmas);
      str = str.replace(":", "=");
      url = "?" + str;
    }
    return fetch(url)
      .then((response) => response.json())
      .then((res) => {
        return res;
      });
  },
  //   post请求
  post: function post(url, obj) {
    return fetch(url, {
      body: JSON.stringify(obj),
      headers: {
        "content-type": "application/json",
      },
      method: "POST",
    })
      .then((response) => response.json())
      .then((res) => {
        return res;
      });
  },
};

export default http;
